﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace AMS.UI.Controls
{
    /// <summary>
    /// 消息提示辅助类
    /// </summary>
    public class BalloonControl
    {
        /// <summary>
        /// 消息提示辅助类
        /// </summary>
        /// <param name="owner"></param>
        public BalloonControl(Form owner)
        {
            this.owner = owner;
        }

        private Form owner;
        /// <summary>
        ///  消息提示控件的拥有者
        /// </summary>
        public Form Owner
        {
            get { return owner; }
        }

        #region 与提示框相关的API
        private DevComponents.DotNetBar.Balloon balloonCtrl;
        /// <summary>
        /// 显示提示框
        /// </summary>
        /// <param name="text"></param>
        /// <param name="ctrl"></param>
        public void balloon(string text, Control ctrl)
        {
            balloon(string.Empty, text, ctrl);
        }
        /// <summary>
        /// 显示提示框
        /// </summary>
        /// <param name="Caption"></param>
        /// <param name="Text"></param>
        /// <param name="ctrl"></param>
        public void balloon(string Caption, string Text, Control ctrl)
        {
            balloon(Caption, Text, ctrl, -1);
        }
        /// <summary>
        /// 显示提示框
        /// </summary>
        /// <param name="Caption"></param>
        /// <param name="Text"></param>
        /// <param name="ctrl"></param>
        /// <param name="Height"></param>
        public void balloon(string Caption, string Text, Control ctrl, int Height)
        {
            balloon(Caption, Text, ctrl, Height, -1);
        }

        /// <summary>
        /// 显示提示框。
        /// </summary>
        /// <param name="Caption"></param>
        /// <param name="Text"></param>
        /// <param name="ctrl"></param>
        /// <param name="Height"></param>
        /// <param name="waitSeconds">如果为-1则使用默认的时间</param>
        public void balloon(string Caption, string Text, Control ctrl, int Height, int waitSeconds)
        {
            if (balloonCtrl != null && !balloonCtrl.IsDisposed)
            {
                balloonCtrl.Hide();
            }
            else
            {
                balloonCtrl = new DevComponents.DotNetBar.Balloon();
            }

            if (waitSeconds < 0)
            {
                // 使用默认的等待时间
                waitSeconds = 3;
            }

            balloonCtrl.Style = DevComponents.DotNetBar.eBallonStyle.Balloon;
            balloonCtrl.AlertAnimation = DevComponents.DotNetBar.eAlertAnimation.TopToBottom;
            balloonCtrl.AutoScroll = true;
            balloonCtrl.AutoClose = true;
            balloonCtrl.AutoCloseTimeOut = waitSeconds;
            balloonCtrl.Owner = owner;
            balloonCtrl.CaptionText = Caption;
            balloonCtrl.Text = Text;
            balloonCtrl.Width = 200;
            if (Height > 0)
            {
                balloonCtrl.Height = Height;
            }

            balloonCtrl.Show(ctrl, true);
            ctrl.Focus();
        }

        /// <summary>
        /// 关闭显示提示框
        /// </summary>
        public void CloseBaloon()
        {
            if (balloonCtrl != null)
            {
                balloonCtrl.Close();
            }
        }
        #endregion

    }
}
